<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="评论内容" prop="commentContents">
        <el-input
          v-model="queryParams.commentContents"
          placeholder="请输入评论内容"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论媒体文件" prop="commentMediaIds">
        <el-input
          v-model="queryParams.commentMediaIds"
          placeholder="请输入评论媒体文件"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评论用户id" prop="commentUserId">
        <el-input
          v-model="queryParams.commentUserId"
          placeholder="请输入评论用户id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="浏览人数" prop="viewNum">
        <el-input
          v-model="queryParams.viewNum"
          placeholder="请输入浏览人数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="点赞人数" prop="likeNum">
        <el-input
          v-model="queryParams.likeNum"
          placeholder="请输入点赞人数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="踩人数" prop="dislikeNum">
        <el-input
          v-model="queryParams.dislikeNum"
          placeholder="请输入踩人数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="是否采纳" prop="isAccept">
        <el-select v-model="queryParams.isAccept" placeholder="请选择是否采纳" clearable size="small">
          <el-option
            v-for="dict in isAcceptOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
        <el-form-item label="是否车大夫评论" prop="isDoctorComment">
        <el-select v-model="queryParams.isDoctorComment" placeholder="请选择是否车大夫评论" clearable size="small">
          <el-option
            v-for="dict in isDoctorCommentOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="显示顺序" prop="orderNum">
        <el-input
          v-model="queryParams.orderNum"
          placeholder="请输入显示顺序"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        <el-form-item label="投诉建议状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择投诉建议状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wechat:doctorquestioncomment:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wechat:doctorquestioncomment:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wechat:doctorquestioncomment:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wechat:doctorquestioncomment:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="doctorquestioncommentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="评论编号" align="center" prop="commentId" />
      <el-table-column label="评论内容" align="center" prop="commentContents" />
      <el-table-column label="评论媒体文件" align="center" prop="commentMediaIds" />
      <el-table-column label="评论用户id" align="center" prop="commentUserId" />
      <el-table-column label="浏览人数" align="center" prop="viewNum" />
      <el-table-column label="点赞人数" align="center" prop="likeNum" />
      <el-table-column label="踩人数" align="center" prop="dislikeNum" />
      <el-table-column label="是否采纳" align="center" prop="isAccept" :formatter="isAcceptFormat" />
      <el-table-column label="是否车大夫评论" align="center" prop="isDoctorComment" :formatter="isDoctorCommentFormat" />
      <el-table-column label="显示顺序" align="center" prop="orderNum" />
      <el-table-column label="投诉建议状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wechat:doctorquestioncomment:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wechat:doctorquestioncomment:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车大夫问答评论对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="评论内容" prop="commentContents">
          <el-input v-model="form.commentContents" placeholder="请输入评论内容" />
        </el-form-item>
        <el-form-item label="评论媒体文件" prop="commentMediaIds">
          <el-input v-model="form.commentMediaIds" placeholder="请输入评论媒体文件" />
        </el-form-item>
        <el-form-item label="评论用户id" prop="commentUserId">
          <el-input v-model="form.commentUserId" placeholder="请输入评论用户id" />
        </el-form-item>
        <el-form-item label="浏览人数" prop="viewNum">
          <el-input v-model="form.viewNum" placeholder="请输入浏览人数" />
        </el-form-item>
        <el-form-item label="点赞人数" prop="likeNum">
          <el-input v-model="form.likeNum" placeholder="请输入点赞人数" />
        </el-form-item>
        <el-form-item label="踩人数" prop="dislikeNum">
          <el-input v-model="form.dislikeNum" placeholder="请输入踩人数" />
        </el-form-item>
        <el-form-item label="是否采纳">
          <el-radio-group v-model="form.isAccept">
            <el-radio
              v-for="dict in isAcceptOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否车大夫评论">
          <el-radio-group v-model="form.isDoctorComment">
            <el-radio
              v-for="dict in isDoctorCommentOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="显示顺序" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入显示顺序" />
        </el-form-item>
        <el-form-item label="投诉建议状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDoctorquestioncomment, getDoctorquestioncomment, delDoctorquestioncomment, addDoctorquestioncomment, updateDoctorquestioncomment, exportDoctorquestioncomment } from "@/api/wechat/doctorquestioncomment";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 车大夫问答评论表格数据
      doctorquestioncommentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否采纳字典
      isAcceptOptions: [],
      // 是否车大夫评论字典
      isDoctorCommentOptions: [],
      // 投诉建议状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        commentContents: undefined,
        commentMediaIds: undefined,
        commentUserId: undefined,
        viewNum: undefined,
        likeNum: undefined,
        dislikeNum: undefined,
        isAccept: undefined,
        isDoctorComment: undefined,
        orderNum: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sys_comment_is_accept").then(response => {
      this.isAcceptOptions = response.data;
    });
    this.getDicts("sys_is_doctor_comment").then(response => {
      this.isDoctorCommentOptions = response.data;
    });
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /** 查询车大夫问答评论列表 */
    getList() {
      this.loading = true;
      listDoctorquestioncomment(this.queryParams).then(response => {
        this.doctorquestioncommentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 是否采纳字典翻译
    isAcceptFormat(row, column) {
      return this.selectDictLabel(this.isAcceptOptions, row.isAccept);
    },
    // 是否车大夫评论字典翻译
    isDoctorCommentFormat(row, column) {
      return this.selectDictLabel(this.isDoctorCommentOptions, row.isDoctorComment);
    },
    // 投诉建议状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        commentId: undefined,
        commentContents: undefined,
        commentMediaIds: undefined,
        commentUserId: undefined,
        viewNum: undefined,
        likeNum: undefined,
        dislikeNum: undefined,
        isAccept: "0",
        isDoctorComment: "0",
        delFlag: undefined,
        orderNum: undefined,
        status: "0",
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.commentId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车大夫问答评论";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const commentId = row.commentId || this.ids
      getDoctorquestioncomment(commentId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车大夫问答评论";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.commentId != undefined) {
            updateDoctorquestioncomment(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addDoctorquestioncomment(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const commentIds = row.commentId || this.ids;
      this.$confirm('是否确认删除车大夫问答评论编号为"' + commentIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDoctorquestioncomment(commentIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有车大夫问答评论数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDoctorquestioncomment(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>